from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.

def set_cookie(request):
    resp = HttpResponse('设置cookie成功')
    # 设置cookie
    resp.set_cookie('uname','lkpkp',max_age=3600*24*7)
    resp.delete_cookie('uname')
    resp = HttpResponse('删除cookie成功')
    return resp


def get_cookie(request):
    my_cookies=request.COOKIES
    print(my_cookies)
    return HttpResponse('获取cookies成功')


def test_session(request):
    # 设置session
    request.session['goods_id']=1001
    request.session['goods_name']='电脑'
    return HttpResponse('ok')


def get_session(request):
    goods_id=request.session.get('goods_id')
    goods_name=request.session.get('goods_name')
    return HttpResponse(f'获取到编号为{goods_id}的{goods_name}')